﻿Module GenericEvents
    Public Sub TextBoxNumeric_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs)
        Dim wAscii As Integer = 0
        Dim wMsgBox As frmMessage = Nothing

        Try
            wAscii = Convert.ToInt32(e.KeyChar)

            If (wAscii >= Keys.D0 And wAscii <= Keys.D9) Or wAscii = Keys.Back Or wAscii = 44 Then 'Coma Then
                If wAscii = 44 Then
                    If Not DirectCast(sender, TextBox).Text.Contains(e.KeyChar) Then
                        e.Handled = False
                    Else
                        e.Handled = True
                    End If
                Else
                    e.Handled = False
                End If
            Else
                e.Handled = True
            End If
        Catch ex As Exception
            wMsgBox = New frmMessage
            wMsgBox.ShowMessage("Excepción", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try
    End Sub

    Public Sub TextBoxCuit_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs)
        Dim wAscii As Integer = 0
        Dim txtCuit As TextBox = DirectCast(sender, TextBox)
        Dim wMsgBox As frmMessage = Nothing

        Try
            wAscii = Convert.ToInt32(e.KeyChar)
            If wAscii = Keys.Back Or wAscii = Keys.Delete Then Return

            'Estructura del CUIT/L
            '(*) La primer parte se compone de dos dígitos: 20 para varones, 27 para mujeres.
            '(*) La segunda parte se encuentra integrada por ocho dígitos.
            '(*) La tercer parte del número esta compuesta por un dígito.
            If txtCuit.TextLength = 11 Then
                'xx-xxxxxxxx
                txtCuit.Text = String.Concat(txtCuit.Text, "-")
                txtCuit.SelectionStart = txtCuit.TextLength
            End If

        Catch ex As Exception
            wMsgBox = New frmMessage
            wMsgBox.ShowMessage("Excepción", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try
    End Sub
End Module
